#include "stdafx.h"
#include "ado/Deletes.h"
#include "ado/DbMysql.h"
#include "standard/nstring.h"
//#include"ado/fun_sets.h"
Deletes *Deletes::_init = NULL; 

Deletes* Deletes::init(void* db)
{
    _init = new Deletes(db);
    return _init;
}

Deletes::Deletes(void *db)
{
    m_db->classname.clear();
    m_db->database.clear();
    
    m_db = (tDataBase*) db;       
    this->m_classname = m_db->classname;
    
    if (!(m_db->database).empty()) {
        m_dbname = m_db->database;
    }
}

int Deletes::destory(const char *tokens, ...)
{
    std::string wheres, que;
    va_list vp; 
    va_start(vp, tokens);   
    
    this->findByArray(tokens, vp);
    va_end(vp);
    
    wheres = this->getWhere();
    this->m_classname = tolower_str(this->m_classname);
    	//GetFunInstance("tolower_str",this->m_classname,this->m_classname);
    que = "delete from " + m_dbname + "."  
            + m_prefix + this->m_classname
            + " where " + wheres;
            
    DbMysql::instance()->execute(que.c_str());
    return true;
}

Deletes::~Deletes()
{
    m_db->database.clear();
    m_db->classname.clear();
}

